/**
 * @Author: ls <ls-mac>
 * @Date:   2019-09-23 00:20:53
 * @Last modified by:   ls-mac
 * @Last modified time: 2019-10-30 01:27:42
 */
import { orderDetail, orderCancel, orderCommit, orderEdit } from 'services/order';

export default {
  namespace: 'orderDetail',
  state: {
    info: {},
  },

  effects: {
    *orderDetail({ payload, callback }, { call, put }) {
      const response = yield call(orderDetail, payload);
      yield put({
        type: 'saveInfo',
        payload: response,
      });
      if (callback) callback(response);
    },
    *orderCancel({ payload, callback }, { call, put }) {
      const response = yield call(orderCancel, payload);
      if (callback) {
        callback(response);
      }
    },
    *orderCommit({ payload, callback }, { call, put }) {
      const response = yield call(orderCommit, payload);
      if (callback) {
        callback(response);
      }
    },
    *orderEdit({ payload, callback }, { call, put }) {
      const response = yield call(orderEdit, payload);
      if (callback) {
        callback(response);
      }
    },
  },

  reducers: {
    saveInfo(state, action) {
      const { data } = action.payload;
      return {
        ...state,
        info: data,
      };
    },
  },
};
